<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>playwright自动化测试(2) | 梧桐的学习日记</title><meta name="author" content="梧桐影下月光卧"><meta name="copyright" content="梧桐影下月光卧"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="更为详细的教程，建议查看业内大咖崔庆才的博客，非常多的基础知识。https:&#x2F;&#x2F;cuiqingcai.com&#x2F;202262.html错误解决pip安装过程中出现下发VC++ 14错误的，安装下面的这个微软包error: Microsoft Visual C++ 14.0 is required. Get it with &quot;Build Tools for Visual Studio&amp;quo">
<meta property="og:type" content="article">
<meta property="og:title" content="playwright自动化测试(2)">
<meta property="og:url" content="https://acwy.fun/2023/10/29/playwright%E8%87%AA%E5%8A%A8%E5%8C%962/index.html">
<meta property="og:site_name" content="梧桐的学习日记">
<meta property="og:description" content="更为详细的教程，建议查看业内大咖崔庆才的博客，非常多的基础知识。https:&#x2F;&#x2F;cuiqingcai.com&#x2F;202262.html错误解决pip安装过程中出现下发VC++ 14错误的，安装下面的这个微软包error: Microsoft Visual C++ 14.0 is required. Get it with &quot;Build Tools for Visual Studio&amp;quo">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://upyun.acwy.fun/acwy.fun/playwright.png">
<meta property="article:published_time" content="2023-10-29T13:21:28.000Z">
<meta property="article:modified_time" content="2023-11-29T10:06:25.936Z">
<meta property="article:author" content="梧桐影下月光卧">
<meta property="article:tag" content="python">
<meta property="article:tag" content="自动化">
<meta property="article:tag" content="爬虫">
<meta property="article:tag" content="playwright">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://upyun.acwy.fun/acwy.fun/playwright.png"><link rel="shortcut icon" href="/img/logo.png"><link rel="canonical" href="https://acwy.fun/2023/10/29/playwright%E8%87%AA%E5%8A%A8%E5%8C%962/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'playwright自动化测试(2)',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-11-29 18:06:25'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.2"></head><body><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pace-js/themes/blue/pace-theme-minimal.min.css"/><script src="https://cdn.jsdelivr.net/npm/pace-js/pace.min.js"></script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="/img/logo.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">28</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">35</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 目录</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg fixed" id="page-header" style="background-image: url('https://upyun.acwy.fun/acwy.fun/playwright.png')"><nav id="nav"><span id="blog-info"><a href="/" title="梧桐的学习日记"><span class="site-name">梧桐的学习日记</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 目录</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">playwright自动化测试(2)</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-10-29T13:21:28.000Z" title="发表于 2023-10-29 21:21:28">2023-10-29</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-11-29T10:06:25.936Z" title="更新于 2023-11-29 18:06:25">2023-11-29</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">766</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>3分钟</span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="更为详细的教程，建议查看业内大咖崔庆才的博客，非常多的基础知识。https-cuiqingcai-com-202262-html"><a href="#更为详细的教程，建议查看业内大咖崔庆才的博客，非常多的基础知识。https-cuiqingcai-com-202262-html" class="headerlink" title="更为详细的教程，建议查看业内大咖崔庆才的博客，非常多的基础知识。https://cuiqingcai.com/202262.html"></a>更为详细的教程，建议查看业内大咖崔庆才的博客，非常多的基础知识。<a target="_blank" rel="noopener" href="https://cuiqingcai.com/202262.html">https://cuiqingcai.com/202262.html</a></h2><h2 id="错误解决"><a href="#错误解决" class="headerlink" title="错误解决"></a>错误解决</h2><p><strong>pip安装过程中出现下发VC++ 14错误的，安装下面的这个微软包</strong><br><code>error: Microsoft Visual C++ 14.0 is required. Get it with &quot;Build Tools for Visual Studio&quot;</code><br><a target="_blank" rel="noopener" href="https://pan.baidu.com/s/1GgLLcGTMj80JZSvfg1LuYw?pwd=7777">https://pan.baidu.com/s/1GgLLcGTMj80JZSvfg1LuYw?pwd=7777</a></p>
<h2 id="百度图片下载小例子-风景图片"><a href="#百度图片下载小例子-风景图片" class="headerlink" title="百度图片下载小例子(风景图片)"></a>百度图片下载小例子(风景图片)</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> playwright.sync_api <span class="keyword">import</span> sync_playwright</span><br><span class="line"><span class="keyword">import</span> wget</span><br><span class="line"></span><br><span class="line"><span class="keyword">with</span> sync_playwright() <span class="keyword">as</span> p:</span><br><span class="line">    <span class="comment"># 可以选择chromium、firefox和webkit运行chrome浏览器</span></span><br><span class="line">    <span class="comment"># False是有头模式，默认为true是无头模式</span></span><br><span class="line">    browser = p.chromium.launch(headless=<span class="literal">False</span>)</span><br><span class="line">    context = browser.new_context()</span><br><span class="line">    <span class="comment"># 打开新页面</span></span><br><span class="line">    page = context.new_page()</span><br><span class="line">    <span class="comment"># 调到指定页面</span></span><br><span class="line">    page.goto(<span class="string">&#x27;https://image.baidu.com/search/index?tn=baiduimage&amp;ps=1&amp;ct=201326592&amp;lm=-1&amp;cl=2&amp;nc=1&amp;ie=utf-8&amp;dyTabStr=MTEsMCw0LDYsMSwzLDUsMiw4LDcsOQ%3D%3D&amp;word=%E9%A3%8E%E6%99%AF&#x27;</span>)</span><br><span class="line">    imgs = page.query_selector_all(<span class="string">&#x27;img&#x27;</span>)</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(imgs)):</span><br><span class="line">        url = imgs[i].get_attribute(<span class="string">&#x27;src&#x27;</span>)</span><br><span class="line">        <span class="keyword">try</span>:</span><br><span class="line">            wget.download(url, <span class="string">&#x27;./&#x27;</span> + <span class="built_in">str</span>(i) + <span class="string">&#x27;.jpg&#x27;</span>)</span><br><span class="line">        <span class="keyword">except</span> Exception <span class="keyword">as</span> e:</span><br><span class="line">            <span class="built_in">print</span>(e)</span><br><span class="line">    <span class="comment"># 关闭</span></span><br><span class="line">    browser.close()</span><br></pre></td></tr></table></figure>

<h2 id="一些高级功能"><a href="#一些高级功能" class="headerlink" title="一些高级功能"></a>一些高级功能</h2><h3 id="事件监听"><a href="#事件监听" class="headerlink" title="事件监听"></a>事件监听</h3><blockquote>
<p>response 事件，同时将回调方法设置为 on_response</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">on_response</span>(<span class="params">response</span>):</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">f&#x27;Statue <span class="subst">&#123;response.status&#125;</span>: <span class="subst">&#123;response.url&#125;</span>&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">with</span> sync_playwright() <span class="keyword">as</span> p:</span><br><span class="line">    browser = p.chromium.launch(headless=<span class="literal">False</span>)</span><br><span class="line">    page = browser.new_page()</span><br><span class="line">    page.on(<span class="string">&#x27;response&#x27;</span>, on_response)</span><br><span class="line">    page.goto(<span class="string">&#x27;https://spa6.scrape.center/&#x27;</span>)</span><br><span class="line">    page.wait_for_load_state(<span class="string">&#x27;networkidle&#x27;</span>)</span><br><span class="line">    browser.close()</span><br><span class="line"><span class="comment"># 结果：正好对应浏览器 Network 面板中所有的请求和响应内容</span></span><br><span class="line"><span class="comment"># Statue 200: https://spa6.scrape.center/</span></span><br><span class="line"><span class="comment"># Statue 200: https://spa6.scrape.center/css/app.ea9d802a.css</span></span><br><span class="line"><span class="comment"># ...</span></span><br><span class="line"><span class="comment"># 修改一下，直接拦截了ajax</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">on_response</span>(<span class="params">response</span>):</span><br><span class="line">    <span class="keyword">if</span> <span class="string">&#x27;/api/movie/&#x27;</span> <span class="keyword">in</span> response.url <span class="keyword">and</span> response.status == <span class="number">200</span>:</span><br><span class="line">        <span class="built_in">print</span>(response.json())</span><br><span class="line"><span class="comment"># &#123;&#x27;count&#x27;: 100, &#x27;results&#x27;: [&#123;&#x27;id&#x27;: 1, &#x27;name&#x27;: ......</span></span><br></pre></td></tr></table></figure>

<h3 id="网络劫持"><a href="#网络劫持" class="headerlink" title="网络劫持"></a>网络劫持</h3><p>最后再介绍一个实用的方法 route<br>可以实现一些网络劫持和修改操作，比如修改 request 的属性，修改 response 响应结果等。</p>
<ol>
<li><p>取消图片加载</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">cancel_request</span>(<span class="params">route, request</span>):</span><br><span class="line">    route.abort()</span><br><span class="line"></span><br><span class="line">page.route(re.<span class="built_in">compile</span>(<span class="string">r&quot;(\.png)|(\.jpg)&quot;</span>), cancel_request)</span><br><span class="line">page.goto(<span class="string">&quot;https://spa6.scrape.center/&quot;</span>)</span><br><span class="line">page.wait_for_load_state(<span class="string">&#x27;networkidle&#x27;</span>)</span><br><span class="line">page.screenshot(path=<span class="string">&#x27;no_picture.png&#x27;</span>)</span><br><span class="line">browser.close()</span><br></pre></td></tr></table></figure>
<p>调用了 route 方法，第一个参数通过正则表达式传入了匹配的 URL 路径<br>这里代表的是任何包含 .png 或 .jpg 的链接，遇到这样的请求，会回调 cancel_request 方法处理<br>cancel_request 方法可以接收两个参数，一个是 route，代表一个 CallableRoute 对象<br>另外一个是 request，代表 Request 对象。<br>这里我们直接调用了 route 的 abort 方法，取消了这次请求，所以最终导致的结果就是图片的加载全部取消了。</p>
<blockquote>
<p>在爬虫的过程中，浏览器中是否把图片加载出来不重要，可以提高整个页面的加载速度，提高爬取效率。</p>
</blockquote>
</li>
<li><p>替换成本地文件</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>Hack Response<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">h1</span>&gt;</span>Hack Response<span class="tag">&lt;/<span class="name">h1</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>下面的例子是，再进入这个网站，网页标题和内容只会显示<code>Hack Response</code>，而不是原本的内容</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">modify_response</span>(<span class="params">route, request</span>):</span><br><span class="line">    route.fulfill(path=<span class="string">&quot;./custom_response.html&quot;</span>)</span><br><span class="line">page.route(<span class="string">&#x27;/&#x27;</span>, modify_response)</span><br><span class="line">page.goto(<span class="string">&quot;https://spa6.scrape.center/&quot;</span>)</span><br></pre></td></tr></table></figure></li>
</ol>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://acwy.fun">梧桐影下月光卧</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://acwy.fun/2023/10/29/playwright%E8%87%AA%E5%8A%A8%E5%8C%962/">https://acwy.fun/2023/10/29/playwright%E8%87%AA%E5%8A%A8%E5%8C%962/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://acwy.fun" target="_blank">梧桐的学习日记</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/python/">python</a><a class="post-meta__tags" href="/tags/%E8%87%AA%E5%8A%A8%E5%8C%96/">自动化</a><a class="post-meta__tags" href="/tags/%E7%88%AC%E8%99%AB/">爬虫</a><a class="post-meta__tags" href="/tags/playwright/">playwright</a></div><div class="post_share"><div class="social-share" data-image="https://upyun.acwy.fun/acwy.fun/playwright.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/img/wechatpay.png" target="_blank"><img class="post-qr-code-img" src= "" data-lazy-src="/img/wechatpay.png" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="/img/alipay.png" target="_blank"><img class="post-qr-code-img" src= "" data-lazy-src="/img/alipay.png" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/11/15/%E6%BB%A1%E5%B1%8F%E7%9A%84%E5%B9%BF%E5%91%8A%EF%BC%8C%E5%A4%AA%E7%83%A6%E4%BA%BA%E4%BA%86/" title="满屏的广告，太烦人了"><img class="cover" src= "" data-lazy-src="https://upyun.acwy.fun/acwy.fun/litiaotiao.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">满屏的广告，太烦人了</div></div></a></div><div class="next-post pull-right"><a href="/2023/10/13/playwright%E8%87%AA%E5%8A%A8%E5%8C%961/" title="playwright自动化测试(1)"><img class="cover" src= "" data-lazy-src="https://upyun.acwy.fun/acwy.fun/playwright.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">playwright自动化测试(1)</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2022/01/10/Beautifulsoup4/" title="1.1 BeautifulSoup简单介绍"><img class="cover" src= "" data-lazy-src="https://pic1.zhimg.com/v2-a4c6b2b3504284423e625419eef9760c_r.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-01-10</div><div class="title">1.1 BeautifulSoup简单介绍</div></div></a></div><div><a href="/2023/10/13/playwright%E8%87%AA%E5%8A%A8%E5%8C%961/" title="playwright自动化测试(1)"><img class="cover" src= "" data-lazy-src="https://upyun.acwy.fun/acwy.fun/playwright.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-10-13</div><div class="title">playwright自动化测试(1)</div></div></a></div><div><a href="/2023/04/10/xpath/" title="1.2 xpath简单介绍"><img class="cover" src= "" data-lazy-src="https://www.w3cschool.cn/attachments/image/20161103/1478161528585228.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-04-10</div><div class="title">1.2 xpath简单介绍</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "" data-lazy-src="/img/logo.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">梧桐影下月光卧</div><div class="author-info__description">分享个人学习路上的小知识</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">28</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">35</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://beau.acwy.fun"><i class="fa-solid fa-envelope"></i><span>点击联系我</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content"><b> <font color="#e66b6d">欢</font> <font color="#e66d98">迎</font> <font color="#e66cc6">访</font> <font color="#cc6de6">问</font> <font color="#9770e6">a</font> <font color="#6d93e6">c</font> <font color="#6fcde6">w</font> <font color="#72e6b6">y</font> <font color="#72e689">的</font> <font color="#99e670">学</font> <font color="#cde670">习</font> <font color="#e6df72">日</font> <font color="#e6c073">记</font> </b> <p align="center"> <img src= "" data-lazy-src="https://upyun.acwy.fun/acwy.fun/公告1.gif" width="50" alt="mao"> </p> <p align="center">微信：acwy0718</p> <p align="center">邮箱：awy0718@gmail.com</p></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9B%B4%E4%B8%BA%E8%AF%A6%E7%BB%86%E7%9A%84%E6%95%99%E7%A8%8B%EF%BC%8C%E5%BB%BA%E8%AE%AE%E6%9F%A5%E7%9C%8B%E4%B8%9A%E5%86%85%E5%A4%A7%E5%92%96%E5%B4%94%E5%BA%86%E6%89%8D%E7%9A%84%E5%8D%9A%E5%AE%A2%EF%BC%8C%E9%9D%9E%E5%B8%B8%E5%A4%9A%E7%9A%84%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E3%80%82https-cuiqingcai-com-202262-html"><span class="toc-number">1.</span> <span class="toc-text">更为详细的教程，建议查看业内大咖崔庆才的博客，非常多的基础知识。https:&#x2F;&#x2F;cuiqingcai.com&#x2F;202262.html</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%94%99%E8%AF%AF%E8%A7%A3%E5%86%B3"><span class="toc-number">2.</span> <span class="toc-text">错误解决</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%99%BE%E5%BA%A6%E5%9B%BE%E7%89%87%E4%B8%8B%E8%BD%BD%E5%B0%8F%E4%BE%8B%E5%AD%90-%E9%A3%8E%E6%99%AF%E5%9B%BE%E7%89%87"><span class="toc-number">3.</span> <span class="toc-text">百度图片下载小例子(风景图片)</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%80%E4%BA%9B%E9%AB%98%E7%BA%A7%E5%8A%9F%E8%83%BD"><span class="toc-number">4.</span> <span class="toc-text">一些高级功能</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8B%E4%BB%B6%E7%9B%91%E5%90%AC"><span class="toc-number">4.1.</span> <span class="toc-text">事件监听</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BD%91%E7%BB%9C%E5%8A%AB%E6%8C%81"><span class="toc-number">4.2.</span> <span class="toc-text">网络劫持</span></a></li></ol></li></ol></div></div></div></div></main><footer id="footer" style="background-image: url('https://upyun.acwy.fun/acwy.fun/playwright.png')"><div id="footer-wrap"><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text"><div> <a href="https://beian.miit.gov.cn/" target="_blank">豫ICP备2023010490号-1</a> </div> <div> <a style="display:flex;justify-content:center;align-items:center;" target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=41152402000204"> <img src= "" data-lazy-src="/img/beian.png" style="width:20px;height:20px;margin:0 5px"> <span>豫公网安备 41152402000204号</span> </a> </div> <div> <a style="display:flex;justify-content:center;" href="https://www.upyun.com/?utm_source=lianmeng&utm_medium=referral" target="_blank"> <span>本网站由</span> <img style="height:30px;margin:0 3px" src= "" data-lazy-src="/img/upyun_logo5.png"> <span>提供CDN加速/云存储服务</span> </a> <div/></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><div class="js-pjax"></div><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/fireworks.min.js"></script><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-nest.min.js"></script></div></body></html>